Instantiating Applets
After you have created a session, located the applet, and created an AWT context for the applet, you can instantiate it. An instantiated applet is defined by anJMAppletViewerRef
object, and you use theJMNewAppletViewer
function to create one. Listing 1-11 shows an example of instantiating an applet.Listing 1-11 Instantiating an applet
JMAppletSecurity securitySettings = { kJMVersion, /* should be kJMVersion */ eAppletHostAccess,/* applet network access option */ eLocalAppletAccess,/* applet access to local file system */ true, /* restrict system.access packages */ true /* restrict system.define packages */ true, /* restrict application.access packages */ true /* restrict application.define packages */ }; JMAppletViewerCallbacks viewerCallbacks = { kJMVersion, /* should be kJMVersion */ MyShowDocument,/* showDocument callback */ MySetStatusMsg /* setMessage callback */ }; JMAppletViewerRef viewer; err = JMNewAppletViewer(&viewer, context, locatorRef, appletIndex, &securitySettings, &viewerCallbacks, 0); /* reload the applet to get it going */ if (err == noErr) { err = JMReloadApplet(viewer); }TheJMNewAppletViewer
function requires you to pass a security options data structure indicating the following security settings:
If you want to determine the current security levels for a particular applet, you can use the
- The applet network access field designates the applet's level of network access. Typically you should set this to
eAppletHostAccess
to indicate that an applet can access only its host server. See "Applet Security Indicators" for a list of available options.- The applet local file system access field designates whether an applet can access files stored on the host computer. Typically you should set this to
eLocalAppletAccess
to indicate that only an applet stored locally can access the local file system. See "Applet Security Indicators" for a list of available options.- The next four fields are flags that let you specify that whether to allow class access or class definitions outside the
java.*
classes. A flag that is set to true restricts access to the packages defined in the corresponding property:
mrj.security.system.access
mrj.security.system.define
mrj.security.application.access
mrj.security.application.define
See "Applet Security Structure" for more information about using these flags.
JMGetAppletViewerSecurity
function. To change existing security levels, you can use theJMSetAppletViewerSecurity
function.In addition, you must define two callbacks,
MyShowDocument
andMySetStatusMsg
, when calling theJMNewAppletViewer
function. TheMyShowDocument
function displays the contents of a URL passed back from the applet, andMySetStatusMsg
displays any status messages the applet may pass to the application. You must also specify the index of the applet you want to instantiate (as returned by theJMCountApplets
function).After you have instantiated the applet viewer object, you must load and execute the applet code by calling the function
JMReloadApplet
.You can set or retrieve client data associated with the applet by using the functions
JMSetAppletViewerData
andJMGetAppletViewerData
.At any time you can stop execution of the applet by calling the
JMSuspendApplet
function and resume it by calling theJMResumeApplet
function. If you want to restart the applet without reloading it from the server, use theJMRestartApplet
function.When you are finished with an applet, you can dispose of it by calling the
JMDisposeAppletViewer
function. This function automatically halts applet execution and removes any frames associated with the applet.